package ReviewTest;

import java.util.Random;
import java.util.Scanner;

public class demo03 {
    public static void main(String[] args) {
        //创建数组
        int[] arr = new int[10];
        //创建随机数
        Random r = new Random();
        System.out.print("[");
        for (int i = 0; i < arr.length; i++) {
            arr[i] = r.nextInt(2, 51);
            if (i == arr.length - 1) {
                System.out.print(arr[i] + "]");
                break;
            }
            System.out.print(arr[i] + ",");
        }
        System.out.println();
        getNum(arr);
        System.out.println(getCount(arr));
    }

    public static void getNum(int[] arr) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要查询的数字");
        int num = sc.nextInt();
        int index = -1;
        for (int i = 0; i < arr.length; i++) {
            if (num == arr[i]) {
                index = i;
            }
        }
        if (index >= 0) {
            System.out.println(index);
        } else {
            System.out.println("不存在");
        }
    }

    public static int getCount(int[] arr) {
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        double avrage = sum / arr.length;
        System.out.println("平均值为：" + avrage);
        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] < avrage) {
                count++;
            }
        }
        return count;
    }
}
